package dhu.cst.jnlwt.jiangnan181310209liwanting181310302.tally.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

import dhu.cst.jnlwt.jiangnan181310209liwanting181310302.tally.R;
import dhu.cst.jnlwt.jiangnan181310209liwanting181310302.tally.entity.TrendBean;

public class TrendAdapter extends BaseAdapter {
    private ArrayList<TrendBean> msgList;
    private LayoutInflater mInflater;

    public TrendAdapter(ArrayList<TrendBean> msgList, Context context){
        this.msgList = msgList;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return msgList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if(convertView == null){
            view = mInflater.inflate(R.layout.item_listview_linechart,null);
            viewHolder = new ViewHolder();
            viewHolder.month = view.findViewById(R.id.month);
            viewHolder.month_expenditure = view.findViewById(R.id.month_expenditure);
            viewHolder.month_income = view.findViewById(R.id.month_income);
            view.setTag(viewHolder);
        }
        else{
            view = convertView;
            viewHolder = (ViewHolder)view.getTag();
        }
        viewHolder.month.setText(msgList.get(position).getMonth());
        viewHolder.month_income.setText(msgList.get(position).getIncome());
        viewHolder.month_expenditure.setText(msgList.get(position).getExpenditure());
        return view;
    }

    static class ViewHolder{
        TextView month;
        TextView month_income;
        TextView month_expenditure;
    }
}
